﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace ShkSimulation.desktop.component.tools {
    public partial class MessageBoxForm : Form {
        
        public MessageBoxForm() {
            InitializeComponent();
        }
        
        public MessageBoxDialogResult MessageBoxDialogResult { get; set; }

        private void CertainButton_Click(object sender, EventArgs e) {
            this.MessageBoxDialogResult = NotNoticeAgainCheckBox.Checked ? 
                MessageBoxDialogResult.OKIgnore:
                MessageBoxDialogResult.OK;
            this.Close();
        }

        private void CancelButton_Click(object sender, EventArgs e) {
            this.MessageBoxDialogResult = NotNoticeAgainCheckBox.Checked ? 
                MessageBoxDialogResult.CancelIgnore:
                MessageBoxDialogResult.Cancel;
            this.Close();
        }

        public static MessageBoxDialogResult GetMessageResult(string title = "提示", string message = "确认吗？", bool showNotNotice = true, MessageBoxImage messageBoxIcon = MessageBoxImage.Question) {
            MessageBoxForm inputForm = new MessageBoxForm();
            inputForm.Text = title;
            inputForm.NotNoticeAgainCheckBox.Visible = showNotNotice;
            inputForm.Infolabel.Text = message;
            inputForm.IconBox.Image = SelectImage(messageBoxIcon);
            inputForm.ShowDialog();
            return inputForm.MessageBoxDialogResult;
        }
        
        public static bool Ignore(MessageBoxDialogResult result) {
            return (result & MessageBoxDialogResult.Ignore) != 0;
        }
        
        private static Image SelectImage(MessageBoxImage messageBoxIcon) {
            switch (messageBoxIcon) {
                case MessageBoxImage.Information:
                    return SystemIcons.Information.ToBitmap();
                case MessageBoxImage.Question:
                    return SystemIcons.Question.ToBitmap();
                case MessageBoxImage.Warning:
                    return SystemIcons.Warning.ToBitmap();
                case MessageBoxImage.Application:
                    return SystemIcons.Application.ToBitmap();
                case MessageBoxImage.Asterisk:
                    return SystemIcons.Asterisk.ToBitmap();
                case MessageBoxImage.Error:
                    return SystemIcons.Error.ToBitmap();
                case MessageBoxImage.Exclamation:
                    return SystemIcons.Exclamation.ToBitmap();
                case MessageBoxImage.Hand:
                    return SystemIcons.Hand.ToBitmap();
                case MessageBoxImage.WinLogo:
                    return SystemIcons.WinLogo.ToBitmap();
                case MessageBoxImage.Shield:
                    return SystemIcons.Shield.ToBitmap();
                default:
                    return SystemIcons.Information.ToBitmap();
            }
        }

    }

    public enum MessageBoxImage {
        Application,
        Asterisk,
        Error,
        Exclamation,
        Hand,
        Information,
        Question,
        Warning,
        WinLogo,
        Shield,
    }
    
    [Flags]
    public enum MessageBoxDialogResult {
        OK = 0x1,
        Cancel = 0x2,        
        OKIgnore = 0x4,
        CancelIgnore = 0x8,
        Ignore = 0x16,
    }

}
